# -*- coding: utf-8 -*-
import shlex
import DBLink.dbHelp

dbHelp = DBLink.dbHelp


# 分页查询操作
def FY_Paging(Num_Now, AllRowNum, EveryPageHadNum):
    _respon = {"number_BeginGetRowNumer": "", "number_EveryPageHadNum": "", "number_AllPageNumer": "",
               "number_PageNumer_Now": ""}

    # Num_Now  输入的当前页数,
    # AllRowNum  输入的总记录数,
    # EveryPageHadNum  输入的每页查询多少条记录

    number_AllRowNum = 0  # 总记录数
    number_EveryPageHadNum = 0  # 每页查询多少条记录
    number_PageNumer_Now = 0  # 当前页数
    number_AllPageNumer = 0  # 总页数
    number_BeginGetRowNumer = 0  # 开始取值的行号

    # 执行计算
    number_PageNumer_Now = Num_Now
    number_AllRowNum = int(AllRowNum)
    number_EveryPageHadNum = EveryPageHadNum
    if number_AllRowNum % number_EveryPageHadNum == 0:
        number_AllPageNumer = number_AllRowNum / number_EveryPageHadNum
    else:
        number_AllPageNumer = number_AllRowNum / number_EveryPageHadNum + 1
    if number_AllPageNumer < Num_Now:
        number_BeginGetRowNumer = 0
        number_PageNumer_Now = 1

    else:
        number_BeginGetRowNumer = (number_PageNumer_Now - 1) * number_EveryPageHadNum
    _respon["number_BeginGetRowNumer"] = number_BeginGetRowNumer
    _respon["number_EveryPageHadNum"] = number_EveryPageHadNum
    _respon["number_AllPageNumer"] = number_AllPageNumer
    _respon["number_PageNumer_Now"] = number_PageNumer_Now

    return _respon


